package org.example.topicdata;

public class DealTopicSteam {
    public Topic deal(String str){
        Topic topic = new Topic();
        int ID;
        String topicName;
        String Select_A,Select_B,Select_C,Select_D;
        String ans;

        int ID_I;
        int topicName_I;
        int Select_A_I,Select_B_I,Select_C_I,Select_D_I;
        int ans_I;

        if(str.startsWith("添加题目")){
            ID_I = str.indexOf("题目ID");
            topicName_I = str.indexOf("题目内容");
            Select_A_I = str.indexOf("选项A");
            Select_B_I = str.indexOf("选项B");
            Select_C_I = str.indexOf("选项C");
            Select_D_I = str.indexOf("选项D");
            ans_I = str.indexOf("答案");

            ID =Integer.parseInt(str.substring(ID_I+5,topicName_I));
            topicName = str.substring(topicName_I + 5,Select_A_I);
            Select_A = str.substring(Select_A_I + 4,Select_B_I);
            Select_B = str.substring(Select_B_I + 4,Select_C_I);
            Select_C = str.substring(Select_C_I + 4,Select_D_I);
            Select_D = str.substring(Select_D_I + 4,ans_I);
            ans = str.substring(ans_I + 3);
            System.out.println(ID+topicName+Select_A+Select_B+Select_C+Select_D+ans);
            topic = new Topic(ID,topicName,Select_A,Select_B,Select_C,Select_D,ans);

            return topic;
        } else if (str.startsWith("搜索题目ID")) {
            ID_I = str.indexOf("题目ID");
            ID =Integer.parseInt(str.substring(ID_I+5));
            System.out.println(ID);
            topic.setID(ID);
            return topic;
        } else {
            return topic;
        }

    }
}
